<?php
/**
 * Hols class Image_Lib_LookUp
 *
 * @author daantimmer
 *
 * @package Library
 * @subpackage Image
 */

/**
 * LookUp table class that will iterate through all the available look-up colors.
 *
 * @author daantimmer
 */
class Image_Lib_LookUp{
	
	/**
	 * @var ArrayList;
	 */
	private $table;
	
	/**
	 * Constructor
	 *
	 * @return void
	 */
	public function __construct(){
		$this->table = new ArrayList();
	}
	
	/**
	 * Iterates through the list of available look-up definitions.
	 *
	 * Returns a new Image_RLEObj with the found color, or returns a new Image_RLEObj with index NONE
	 *
	 * @see Image_ColorIndex
	 * @param Image_Lib_Color $color
	 * @return Image_RLEObj
	 */
	public function lookUp(Image_Lib_Color $color){
		$colorIndex = Image_ColorIndex::instance();
		
		foreach($this->table AS $filter){
			$index = $filter->inFilter($color);
			if($index != $colorIndex->NONE){
				return new Image_RLEObj($filter->getColor(),$index);
			}
		}
		
		return new Image_RLEObj(new Image_Lib_Color(0),$colorIndex->NONE);
	}
	
	/**
	 * Adds a lookup definition to the table
	 *
	 * @param Image_Lib_LookUpFilter $filter
	 * @return void
	 */
	public function add(Image_Lib_LookUpFilter $filter){
		$this->table->add($filter);
	}
}